#ifndef __USART_645_H
#define __USART_645_H

#include <stdint.h>
#include "at32f403a_407_board.h"
#include "los_task.h"

// 缓冲区大小定义
#define USART1_RX_BUF_SIZE 256
#define USART1_TX_BUF_SIZE 256
#define ECHO_ENABLED 1

// 接收缓冲区结构体
typedef struct {
    uint8_t buf[USART1_RX_BUF_SIZE];
    volatile uint16_t head;
    volatile uint16_t tail;
    volatile uint16_t count;
} usart1_rx_buf_t;

// 发送缓冲区结构体
typedef struct {
    uint8_t buf[USART1_TX_BUF_SIZE];
    volatile uint16_t head;
    volatile uint16_t tail;
    volatile uint16_t count;
} usart1_tx_buf_t;

extern usart1_rx_buf_t usart1_rx_buf;
extern usart1_tx_buf_t usart1_tx_buf;
// 函数声明
void usart1_645_init(uint32_t baudrate);
void usart1_send_data_it(uint8_t *data, uint16_t len);
void usart1_switch_to_receive(void);
void usart1_switch_to_send(void);
uint16_t usart1_get_rx_data_len(void);
uint16_t usart1_read_rx_data(uint8_t *buf, uint16_t len);
void usart1_clear_rx_buffer(void);
void usart1_echo_handler(void);


#endif